//
//  MtimeMainController.m
//  Mtime2.0
//
//  Created by 凉气的Mac on 16/9/2.
//  Copyright © 2016年 凉气的Mac. All rights reserved.
//

#import "MtimeMainController.h"

#import "HomePageTableViewController.h"

#import "BuyTicketViewController.h"

#import "MarketViewController.h"

#import "DiscoverViewController.h"

#import "MyInfoTableViewController.h"

#import "MtimeNavigationController.h"

#import "TabBarView.h"

#import <Masonry.h>

@interface MtimeMainController ()<TabBarViewDelegate>

@end

@implementation MtimeMainController

-(instancetype)init{

    if (self = [super init]) {
        
        [self setupUI];
    }
    
    return self;
}


#pragma mark --
#pragma mark --设置界面
-(void)setupUI{

    //实例化控制器
    HomePageTableViewController *homePage = [[HomePageTableViewController alloc]init];
    BuyTicketViewController *buyTicket = [[BuyTicketViewController alloc]init];
    MarketViewController *market = [[MarketViewController alloc]init];
    DiscoverViewController *discover = [[DiscoverViewController alloc]init];
    MyInfoTableViewController *myInfo = [[MyInfoTableViewController alloc]init];
    
    NSArray *controllerArray = @[homePage,buyTicket,market,discover,myInfo];
    
    NSMutableArray *navArray = [NSMutableArray array];
    
    for (int i = 0; i < controllerArray.count; i ++) {
        
        UINavigationController *nav = [[UINavigationController alloc]init];
        
        nav.viewControllers = @[controllerArray[i]];
        
        [navArray addObject:nav];
    }
    
    self.viewControllers = navArray;
    
    //添加tabbar按钮
    TabBarView *tabbar = [[TabBarView alloc]init];
    
    tabbar.backgroundColor = [UIColor whiteColor];
    
    tabbar.delegata = self;
    
    [self.view addSubview:tabbar];
    
    [tabbar mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.tabBar);
        
    }];
    
    NSArray *normalImageArray = @[@"home",@"payticket",@"store",@"discover",@"myinfo"];
    
    for (int i = 0; i < navArray.count; i ++) {
        
        UIImage *normalImage = [UIImage imageNamed:normalImageArray[i]];
        
        UIImage *secectImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_on",normalImageArray[i]]];
        
        [tabbar addBtnWithNormal:normalImage andSecect:secectImage];
        
    }
    
}

#pragma mark --
#pragma mark --tabbar代理
-(void)tabBarView:(TabBarView *)tabBarView changeControllerWithIndex:(NSInteger)index{

    self.selectedIndex = index;
    
}




@end





































































